package com.learning.controller;

import com.learning.entity.User;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * Created by hanchuanxing on 2018/10/25.
 */
@Controller
public class HelloController {

    @Value("${app.name}")
    private String name;
    @Value("${app.version}")
    private String version;

    @Resource
    AppConfig appconfig;

    @RequestMapping("/hello")
    public String index(){
        return "Hello World";
    }

    @RequestMapping("/out")
    public Date out(Date sdate){
        return sdate;
    }

    @RequestMapping("/")
    public String index(ModelMap map){
        User user = new User();
        user.setId(1L);
        user.setName("张三");
        user.setAge(20);

        User u1 = new User();
        u1.setId(2L);
        u1.setName("李四");
        u1.setAge(30);

        List<User> users = new ArrayList<User>();
        users.add(user);
        users.add(u1);

        map.addAttribute("users", users);
        return "index";
    }
}
